#ifndef __BITS_HPP__
#define __BITS_HPP__

#include<vector>
#include<iostream>

class Bits
{
public:
    Bits( size_t nbits = 0 ) : _nbits( nbits ), _bits( size_t( ceil( nbits / ( double )sizeof( char ) ) ) )
    {
    }

    void addOneBit( bool v )
    {
        if ( _nbits + 1 > _bits.size() * sizeof( char ) )
            _bits.push_back( 0 );

        _bits[_nbits / sizeof( char )] |= ( v << ( _nbits % sizeof( char ) ) );
        ++_nbits;
    }

    bool operator [] ( int i ) const
    {
        int k = i % sizeof( char );
        return ( _bits[i / sizeof( char )] & ( 1 << k ) );
    }

    void set( int i, bool v )
    {
        _bits[i / sizeof( char )] |= ( v << ( i % sizeof( char ) ) );
    }
private:
    size_t _nbits;
    std::vector<char> _bits;
};

#endif __BITS_HPP__